package com.codeduck.exception.handler;

import com.codeduck.exception.exception.PermissionException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 *  异常统一处理
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2021-12-26
 */
@ControllerAdvice
@Slf4j
public class ControllerExceptionHandler {

    @ExceptionHandler(PermissionException.class)
    @ResponseBody
    public Map<String, Object> handlerPermissionException(PermissionException e) {
        Map<String, Object> map = new HashMap<>();
        log.error("[PermissionException] : {}", e.getMsg());
        map.put("message", e.getMsg());
        return map;
    }
}
